package com.ruoyi.t.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.t.domain.TOrderStyle;
import com.ruoyi.t.mapper.TOrderStyleMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.t.mapper.TOrderUserAddressMapper;
import com.ruoyi.t.domain.TOrderUserAddress;
import com.ruoyi.t.service.ITOrderUserAddressService;

/**
 * 订单供应商发货Service业务层处理
 *
 * @author YY
 * @date 2025-02-09
 */
@Service
public class TOrderUserAddressServiceImpl implements ITOrderUserAddressService
{
    @Autowired
    private TOrderUserAddressMapper tOrderUserAddressMapper;

    @Autowired
    private TOrderStyleMapper tOrderStyleMapper;

    /**
     * 查询订单供应商发货
     *
     * @param id 订单供应商发货主键
     * @return 订单供应商发货
     */
    @Override
    public TOrderUserAddress selectTOrderUserAddressById(Long id)
    {
        return tOrderUserAddressMapper.selectTOrderUserAddressById(id);
    }

    /**
     * 查询订单供应商发货列表
     *
     * @param tOrderUserAddress 订单供应商发货
     * @return 订单供应商发货
     */
    @Override
    public List<TOrderUserAddress> selectTOrderUserAddressList(TOrderUserAddress tOrderUserAddress)
    {
        return tOrderUserAddressMapper.selectTOrderUserAddressList(tOrderUserAddress);
    }

    /**
     * 新增订单供应商发货
     *
     * @param tOrderUserAddress 订单供应商发货
     * @return 结果
     */
    @Override
    public int insertTOrderUserAddress(TOrderUserAddress tOrderUserAddress)
    {
        tOrderUserAddress.setCreateTime(DateUtils.getNowDate());

        TOrderStyle tOrderStyle = tOrderStyleMapper.selectTOrderStyleById(tOrderUserAddress.getOrderStyleId());
        if(tOrderStyle!=null){
            tOrderStyle.setActNum(tOrderStyle.getNum());
            tOrderStyleMapper.updateTOrderStyle(tOrderStyle);
        }

        return tOrderUserAddressMapper.insertTOrderUserAddress(tOrderUserAddress);
    }

    /**
     * 修改订单供应商发货
     *
     * @param tOrderUserAddress 订单供应商发货
     * @return 结果
     */
    @Override
    public int updateTOrderUserAddress(TOrderUserAddress tOrderUserAddress)
    {
        tOrderUserAddress.setUpdateTime(DateUtils.getNowDate());
        return tOrderUserAddressMapper.updateTOrderUserAddress(tOrderUserAddress);
    }

    /**
     * 批量删除订单供应商发货
     *
     * @param ids 需要删除的订单供应商发货主键
     * @return 结果
     */
    @Override
    public int deleteTOrderUserAddressByIds(Long[] ids)
    {
        return tOrderUserAddressMapper.deleteTOrderUserAddressByIds(ids);
    }

    /**
     * 删除订单供应商发货信息
     *
     * @param id 订单供应商发货主键
     * @return 结果
     */
    @Override
    public int deleteTOrderUserAddressById(Long id)
    {
        return tOrderUserAddressMapper.deleteTOrderUserAddressById(id);
    }
}
